home *** CD-ROM | disk | FTP | other *** search
/ Aminet 35 / Aminet 35 (2000)(Schatztruhe)[!][Feb 2000].iso / Aminet / util / libs / MMULib.lha / MMULib / C_Sources / SCSIDMATest.c < prev   
C/C++ Source or Header  |  1999-02-07  |  3KB  |  91 lines

  1. /*****************************************************************
  2.  ** CheckSCSINest                                               **
  3.  **                                                             **
  4.  ** Check the nest count for CachePre/PostDMA                   **
  5.  ** (c) 1998 THOR-Software, inc. Thomas Richter                 **
  6.  *****************************************************************/
  7.  
  8. /// Includes
  9. #include <exec/types.h>
  10. #include <exec/execbase.h>
  11. #include <dos/dos.h>
  12. #include <proto/exec.h>
  13. #include <proto/dos.h>
  14. ///
  15. /// Typedefs
  16. typedef __asm APTR CachePreDMAType(register __a0 APTR virtual,register __a1 LONG *length,register __d0 LONG flags);
  17. typedef __asm void CachePostDMAType(register __a0 APTR virtual,register __a1 LONG *length,register __d0 LONG flags);
  18. ///
  19. /// Protos
  20. int __saveds main(void);
  21. APTR __asm __saveds NewCachePreDMA(register __a0 APTR virtual,register __a1 LONG *length,register __d0 LONG flags);
  22. void __asm __saveds NewCachePostDMA(register __a0 APTR virtual,register __a1 LONG *length,register __d0 LONG flags);
  23. ///
  24. /// Statics
  25. struct ExecBase *SysBase;
  26. struct DosLibrary *DOSBase;
  27. CachePreDMAType *oldpre;
  28. CachePostDMAType *oldpost;
  29. LONG counter;
  30. LONG precounter;
  31. LONG precounternon;
  32. LONG postcounter;
  33. ///
  34.  
  35. /// main
  36. int __saveds main(void)
  37. {
  38.  
  39.         SysBase=*((struct ExecBase **)(4L));
  40.  
  41.         if (DOSBase=(struct DosLibrary *)OpenLibrary("dos.library",37L)) {
  42.                 Disable();
  43.                 oldpre=(CachePreDMAType *)SetFunction((struct Library *)SysBase,-762,(APTR)(&NewCachePreDMA));
  44.                 oldpost=(CachePostDMAType *)SetFunction((struct Library *)SysBase,-768,(APTR)(&NewCachePostDMA));
  45.                 counter=0;
  46.                 precounter=0;
  47.                 postcounter=0;
  48.                 precounternon=0;
  49.                 Enable();
  50.                 Printf("CachePreDMA/PostDMA patches installed. Please start massive\n"
  51.                        "disk activity now, keep the program running for several minutes.\n"
  52.                        "Then remove it with ^C.\n\n");
  53.                 SetSignal(0L,SIGBREAKF_CTRL_C);
  54.                 Wait(SIGBREAKF_CTRL_C);
  55.                 Disable();
  56.                 SetFunction((struct Library *)SysBase,-762,(APTR)(oldpre));
  57.                 SetFunction((struct Library *)SysBase,-768,(APTR)(oldpost));
  58.                 Enable();
  59.                 Printf("The patches have been removed.\n"
  60.                        "The DMA activity counter is %ld. "
  61.                        "CachePreDMA called %ld times,\n"
  62.                        "%ld times without DMA_Continue, "
  63.                        "CachePostDMA called %ld times.\n\n",
  64.                        counter,precounter,precounternon,postcounter);
  65.                 CloseLibrary((struct Library *)DOSBase);
  66.         }
  67.  
  68.         return 0;
  69. }
  70. ///
  71. /// CachePreDMA
  72. APTR __asm __saveds NewCachePreDMA(register __a0 APTR virtual,register __a1 LONG *length,register __d0 LONG flags)
  73. {
  74.         precounter++;
  75.         if (!(flags & DMA_Continue)) {
  76.                 counter++;
  77.                 precounternon++;
  78.         }
  79.         return (*oldpre)(virtual,length,flags);
  80. }
  81. ///
  82. /// CachePostDMA
  83. void __asm __saveds NewCachePostDMA(register __a0 APTR virtual,register __a1 LONG *length,register __d0 LONG flags)
  84. {
  85.         counter--;
  86.         postcounter++;
  87.         (*oldpost)(virtual,length,flags);
  88. }
  89. ///
  90.  
  91.